package 简单.两数之和;

import java.util.HashMap;
import java.util.Map;

/**
 * @author liudingding
 * @ClassName Solution2
 * @description
 * @date 2021/2/8 10:37 上午
 */
public class Solution2 {

    public int[] twoSum(int[] nums, int target) {
        Map<Integer, Integer> map = new HashMap<>();
        for (int i=0; i<nums.length; i++){
            int result = target - nums[i];
            if (map.containsKey(result)){
                return new int[]{map.get(result),i};
            }
            map.put(nums[i],i);
        }
        return new int[]{};
    }
}
